<?php

Raise::load('core.RaiseValidator');

/**
 * RaiseRangeValidator class
 * validates value to be between a min and max value
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package phpraise.core.validator
 * @since 1.2
 */
class RaiseRangeValidator extends RaiseValidator {

    /**
     * The minimum value
     * @var integer|double
     */
    private $min;

    /**
     * The maximum value
     * @var integer|double
     */
    private $max;

    /**
     * Create a new RaiseRegexValidator
     * @param string $regex The regular expression to use.
     */
    function __construct($min, $max){
        $this->min($min);
        $this->max($max);
    }

    /**
     * Get or set the minimum value of the range
     * @param string $m (optional) If set, the new value will be set.
     * @return string
     */
    public function min($m = false){
        if(func_num_args() == 1){
            $this->min = $m;
        }
        return $this->min;
    }

    /**
     * Get or set the maximum value of the range
     * @param string $m (optional) If set, the new value will be set.
     * @return string
     */
    public function max($m = false){
        if(func_num_args() == 1){
            $this->max = $m;
        }
        return $this->max;
    }

    public function validate($value) {
        parent::validate($value);
        return $this->min <= $value && $value <= $this->max;
    }

}
